package com.zhao.invoker;

import com.zhao.command.Command;

import java.util.ArrayList;
import java.util.Iterator;

public class Waitor {

    private ArrayList<Command> commands;

    public Waitor() {
        commands = new ArrayList<>();
    }

    public void setCommand(Command cmd) {
        commands.add(cmd);
    }

    public void orderUp() {
        System.out.println("您有一份新订单......");
        Iterator<Command> iterator = commands.iterator();
        while (iterator.hasNext()) {
            Command next = iterator.next();
            if (next != null) {
                next.execute();
            }
        }
    }
}
